<?php
/* ******************************
	Incoming Tasks aJax actions
   ******************************
*/
	include('../../includes/classes/core.php');
	$action 	= $_REQUEST['act'];
	$data 		= '';
	$error		= '';
	$start		= $_REQUEST['start'];
    $end		= $_REQUEST['end'];
    $client_id	= $_REQUEST['id'];
		
	switch ($action) {
	    case 'get_list':
    	    $count = $_REQUEST['count'];
    	    
    	    $rResult = mysql_query("SELECT		`describe_detail`.`id`,
												`describe`.`date`,
										       	production.`name`,
										       	production_category.`name`,
										       	IF((describe_detail.real_quantity - `describe_detail`.quantity) > 0 , CONCAT('+',(describe_detail.real_quantity - `describe_detail`.quantity)), (describe_detail.real_quantity - `describe_detail`.quantity)) AS diff,
										       	describe_detail.self_cost,
										       	describe_detail.price,
										       	(describe_detail.real_quantity - `describe_detail`.quantity) * describe_detail.self_cost,
										       	(describe_detail.real_quantity - `describe_detail`.quantity) * describe_detail.price
									FROM 		`describe`
									LEFT JOIN 	`describe_detail` ON `describe`.id = describe_detail.describe_id
									LEFT JOIN 	production ON production.id = describe_detail.production_id
									LEFT JOIN 	production_category ON production.id = production_category.id");
			
			$output = array(
				"aaData"	=> array()
			);
			
			while ( $aRow = mysql_fetch_array( $rResult ) )
			{
				$row = array();
				for ( $i = 0 ; $i < $count ; $i++ )
				{
					/* General output */
					$row[] = $aRow[$i];
				}
				$output['aaData'][] = $row;
			}
			
			echo json_encode( $output );

	        break;	    
	    default:
	       	echo "null";
	}
?>